package cn.edu.imnu.controller.web;

import cn.edu.imnu.model.WordMain;
import cn.edu.imnu.service.WordMainService;
import common.model.DataBootstrapTable;
import common.model.ResponseModelBootstrapTable;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * Created with IntelliJ IDEA.
 *
 * @author ranhongmin--2018/3/10
 * Description:
 */
@Controller
@RequestMapping("wordMainAction")
public class WordMainController {
	@Resource
	private WordMainService mainService;

	@RequestMapping("main.json")
	@ResponseBody
	public ResponseModelBootstrapTable main(HttpServletRequest request, DataBootstrapTable dataBootstrapTable) {
		return mainService.main(dataBootstrapTable);
	}

	/**
	 * add
	 *
	 * @param request
	 * @param info
	 * @return
	 */
	@RequestMapping("add.json")
	@ResponseBody
	public ResponseModelBootstrapTable add(HttpServletRequest request, WordMain info) {
		return mainService.doAction(info, "1");
	}


	/**
	 * update
	 *
	 * @param request
	 * @param info
	 * @return
	 */
	@RequestMapping("update.json")
	@ResponseBody
	public ResponseModelBootstrapTable update(HttpServletRequest request, WordMain info) {
		return mainService.doAction(info, "2");
	}

	/**
	 * del
	 *
	 * @param request
	 * @param info
	 * @return
	 */
	@RequestMapping("del.json")
	@ResponseBody
	public ResponseModelBootstrapTable del(HttpServletRequest request, WordMain info) {
		return mainService.doAction(info, "3");
	}

	/**
	 * 获取词条列表
	 *
	 * @param request
	 * @param dataBootstrapTable
	 * @return
	 */
	@RequestMapping("getWordList.json")
	@ResponseBody
	public ResponseModelBootstrapTable getWordList(HttpServletRequest request, DataBootstrapTable dataBootstrapTable) {
		return mainService.getWordList(dataBootstrapTable);
	}

	/**
	 * 获取所有 后台管理
	 *
	 * @param request
	 * @return
	 */
	@RequestMapping("getAllWordList.json")
	@ResponseBody
	public ResponseModelBootstrapTable getAllWordList(HttpServletRequest request) {
		return mainService.getAllWordList();
	}

	/**
	 * 获取词条名 后台管理
	 *
	 * @param request
	 * @param wordId
	 * @return
	 */
	@RequestMapping("getWordNameByWordId.json")
	@ResponseBody
	public String getWordName(HttpServletRequest request, String wordId) {
		return mainService.getWordNameById(wordId);
	}

	/**
	 * 根据ID获取信息
	 *
	 * @param request
	 * @param wordId
	 * @return
	 */
	@RequestMapping("getMainById.json")
	@ResponseBody
	public ResponseModelBootstrapTable getInfoById(HttpServletRequest request, String wordId) {
		ResponseModelBootstrapTable modelBootstrapTable = new ResponseModelBootstrapTable();
		WordMain m = mainService.getInfoById(wordId);
		modelBootstrapTable.setObject(m);
		return modelBootstrapTable;
	}


}
